/*
 * ModifyUser.cpp
 *
 *  Created on: 2013-1-30
 *      Author: Administrator
 */

#include "ModifyUser.h"
ModifyUser::ModifyUser(QWidget *parent):
QDialog(parent), nameLabel("用户名"), userTypeLabel("用户类型"), passwdLabel("用户密码"), mode(0), id(0),
lockCheckBox("是否停用"), modifyButton("修改"), cancleButton("取消"), loginLabel("登录名")
{
	connect(&modifyButton, SIGNAL(clicked()), this, SLOT(slt_modifyOrAdd()));
	connect(&cancleButton, SIGNAL(clicked()), this, SLOT(close()));
	userTypeComoboBox.insertItem(User::SaleManager, "营销经理");
	userTypeComoboBox.insertItem(User::Director, "区域领导");
//	userTypeComoboBox.setCurrentIndex(0);
	layout.addWidget(&nameLabel, 0, 0);
	layout.addWidget(&nameLineEdit, 0, 1, 1, 2);
	layout.addWidget(&loginLabel, 1, 0);
	layout.addWidget(&loginLineEdit, 1, 1, 1, 2);
	layout.addWidget(&userTypeLabel, 2, 0);
	layout.addWidget(&userTypeComoboBox, 2, 1);
	layout.addWidget(&lockCheckBox, 2, 2);
	layout.addWidget(&passwdLabel, 3, 0);
	layout.addWidget(&passwdLineEdit, 3, 1, 1, 2);
	layout.addWidget(&modifyButton, 4, 0);
	layout.addWidget(&cancleButton, 4 ,2);
	this->setLayout(&layout);
	setWindowTitle("修改用户信息");
	setFixedHeight(sizeHint().height());
}

void ModifyUser::setMode(int mode)
{
	qDebug() << "enter void ModifyUser::setMode(int mode)";
	this->mode = mode;
	if(mode == addMode)
	{
		modifyButton.setText("添加用户");
		setWindowTitle("添加用户信息");
	}
	else
	{
		setWindowTitle("修改用户信息");
		modifyButton.setText("确认修改");
	}
}

void ModifyUser::slt_modifyOrAdd()
{
	qDebug() << "enter void ModifyUser::slt_modifyOrAdd()";
	emit sig_modifyOrAdd(mode, id, nameLineEdit.text(), loginLineEdit.text(), userTypeComoboBox.currentIndex(),
			lockCheckBox.isChecked(), passwdLineEdit.text());
	qDebug() << "ModifyUser::slt_modifyOrAdd(), lockCheckBox.isChecked() = " << lockCheckBox.isChecked()
			<< "; userTypeComoboBox.currentIndex() = " << userTypeComoboBox.currentIndex();
	this->close();
}

void ModifyUser::setUi(const int &id, const QString &name, const QString &loginName, const int &type,
		   const bool &locked, const QString &password)
{
	qDebug() << "enter ModifyUser::setUi, arguments: locked = " << locked << ";type is " << type;
	this->id = id;
	nameLineEdit.setText(name);
	loginLineEdit.setText(loginName);
	userTypeComoboBox.setCurrentIndex(type);
	lockCheckBox.setChecked(locked);
	passwdLineEdit.setText(password);
}

ModifyUser::~ModifyUser() {
	// TODO Auto-generated destructor stub
}

